package com.xujl.mvcbind.widget.list;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.widget.NestedScrollView;

public class ListFragmentLayout extends NestedScrollView {
    private AbsFragmentAdapter mAdapter;
    LinearLayout mRootLL;

    public ListFragmentLayout (@NonNull Context context) {
        super(context);
        init(context);
    }

    public ListFragmentLayout (@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public ListFragmentLayout (@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init (Context context) {
        setFillViewport(true);
        mRootLL = new LinearLayout(context);
        mRootLL.setOrientation(LinearLayout.VERTICAL);
        mRootLL.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        addView(mRootLL);
    }

    public AbsFragmentAdapter getAdapter () {
        return mAdapter;
    }

    public void setAdapter (AbsFragmentAdapter adapter) {
        mAdapter = adapter;
        mAdapter.createLayout(this);
    }
}
